package kt03.rx02


fun layout(action: () -> Unit) = action()
fun button(action: () -> Unit) = action()
fun text(action: () -> Unit) = action()

fun main() {

    layout {
        println("layout")
        button {
            println("button")
        }
        text {
            println("text")
        }
    }


    // TODO AndroidManifest.xml 上节课没有说完
    manifest {
        pkg("com.derry.kt_base") // 包名
        permission("android.permission.INTERNET") // 权限

        // 四大组件
        application {  // this == 第二个中转站 Component { activity service }

            activity(".MainActivity") { // this == 第三个中转站 IntentFilter
                intent_filter { // this == 第四个中转站 Sub

                    // action1 action2 action3

                    action("android.intent.action.MAIN")
                    category("android.intent.category.LAUNCHER")
                }
            }

            service(".MyService") {
                intent_filter {

                }
            }

            receiver(".MyCustomReceiver") {
                intent_filter {

                }
            }

            provider(".MyCustomReceiver") {
                intent_filter {

                }
            }
        }
    }
}

class Manifest{
    fun pkg(content:String){}
    fun permission(content: String){}
    fun application(action: Component.() -> Unit):Component{
        val component = Component()
        component.action()
        return component
    }
}
class Sub {
    fun action(content: String) {}
    fun category(content: String) {}
}
class IntentFiler{
    fun intent_filter(action: Sub.() -> Unit){}

}
class Component{
    fun activity(content: String,action: IntentFiler.() -> Unit):IntentFiler{
        val intentFiler = IntentFiler()
        intentFiler.action()
        return intentFiler
    }
    fun service(content: String,action: IntentFiler.() -> Unit):IntentFiler{
        val intentFiler = IntentFiler()
        intentFiler.action()
        return intentFiler
    }

    fun receiver(content: String,action: IntentFiler.() -> Unit):IntentFiler{
        val intentFiler = IntentFiler()
        intentFiler.action()
        return intentFiler
    }

    fun provider(content: String,action: IntentFiler.() -> Unit):IntentFiler{
        val intentFiler = IntentFiler()
        intentFiler.action()
        return intentFiler
    }
}

fun manifest(action: Manifest.() -> Unit):Manifest{
    val manifest = Manifest()
    manifest.action()
    return manifest
}